// views/index/Germanstudy/kedetail/index.js
var BASE_URL = getApp().globalData.BASE_URL

Page({

  /**
   * 页面的初始数据
   */
  data: {
    active: 0,
    xing:5,
    xingxing:5,
    school:'',
    list:'',
    showloading:true,
    show: false,
    name:'',
    tel:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  console.log(options)
  var _this = this
    wx.request({
      url: `${BASE_URL}/study/kechengdetail`,
      method: "POST",
      header: {
        'Content-Type': 'application/json' //GET方式是这个
      },
      data: {
        id: options.id,
      },
      success(res) {
        console.log(res)
        res.data.kecheng_list.forEach((item, index) => {
          item.img = `${BASE_URL}/` + item.img
        })
        res.data.kecheng_detail.detail = res.data.kecheng_detail.detail.replace(/<o:p>/g, '');
        res.data.one.logo= `${BASE_URL}/`+res.data.one.logo
        res.data.kecheng_detail.img= `${BASE_URL}/`+res.data.kecheng_detail.img
        console.log(res.data)
        _this.setData({
          showloading:false,
          school:res.data.one,
          list:res.data.kecheng_detail
        })
      }
    })
  },
  onChange(event) {
 
  },
  showPopup() {
    var phoneNumber = wx.getStorageSync("phoneNumber")
    if(phoneNumber!==''){
      this.setData({ tel: phoneNumber });
    }
    this.setData({ show: true });
  },

  onClose() {
    this.setData({ show: false });
  },
  sure:function(){
    if(this.data.name==''||this.data.tel==''){
      wx.showToast({
        title: '姓名或电话为空',
        icon: 'none',
        duration: 2000
      })
    }else{
    var _this = this
    wx.request({
      url: `${BASE_URL}/activity/yuyuebaoming.html`,
      method: "POST",
      header: {
        'Content-Type': 'application/json' //GET方式是这个
      },
      data: {
        user:_this.data.name,
        tel:_this.data.tel,
        from:'机构',
        want:_this.data.list.type
      },
      success(res) {
        console.log(res)
        _this.setData({ show: false });
        wx.setStorage({
          key: "phoneNumber",
          data: _this.data.tel
        })
        wx.showToast({
          title: '恭喜您，预约成功',
          icon: 'none',
          duration: 2000
        })
      }
    })
  }

  },
  Change(event) {
    console.log(event)
    // this.setData({
    //   xingxing: event.detail,
    // });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})